package cz.proks.easyhelpdesk.gae.api.impl.ws;

import java.util.LinkedList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cz.proks.easyhelpdesk.api.BaseHelpdeskApi;
import cz.proks.easyhelpdesk.api.exception.ApiException;
import cz.proks.easyhelpdesk.api.model.base.AnIdentifiableHelpdeskModel;

public abstract class BaseHelpdeskApiImpl<Entity extends AnIdentifiableHelpdeskModel> extends BaseApiImpl<Entity> implements BaseHelpdeskApi<Entity> {
    
    private final Logger log = LoggerFactory.getLogger(getClass());    
    
    @Override
    protected abstract BaseHelpdeskApi<Entity> getCoreApi();    
        
    @Override
    @RequestMapping(value = "/listForHelpdesk/{helpdeskId}", method = RequestMethod.GET)
    @ResponseBody
    public List<Entity> listForHelpdesk(@PathVariable Long helpdeskId) throws ApiException {
        log.debug("list():: Start with helpdeskId '{}'", helpdeskId);

        List<Entity> entities = null;

        if (getCoreApi() != null)
            entities = getCoreApi().listForHelpdesk(helpdeskId);
        else {
            entities = new LinkedList<Entity>();
            log.warn("get():: Service implementation not found!");
        }

        log.debug("list():: End with {}", (entities == null ? "null list" : "list of " + entities.size() + " elements"));
        return entities;
    }

}
